/*
 * @Description: 
 * @Version: 2.0
 * @Author: Symbol_Yang
 * @Date: 2022-06-07 09:51:24
 * @LastEditors: Symbol_Yang
 * @LastEditTime: 2023-03-20 08:22:44
 */
/**
 * 设备
 * @type {[type]}
 */
 const mongoose = require('mongoose')

 const { Schema } = mongoose
 
 
 const EquipmentSchema = new Schema({
                                                               
     name: { type: String},   //设备名称
 
     code: { type: String},   //设备编号

     wafer_uid: { type: String}, // 芯片唯一编号地址；
 
     cordon: {type: Number}, // 警戒线

     type: {type: Number, enum: [1,2]}, // 类型 1、温度传感器 2、气体传感器

     gas_type: {type: String}, // 气体类型 

     enterprise_id: { type: Schema.Types.ObjectId, ref: 'enterprise', required: true}, //  所属企业

     cabinet_id: { type: Schema.Types.ObjectId, ref: 'cabinet', required: true}, //  所属储存柜

     real_num: { type: Number, default: 0}, // 当前读数；

     real_time: { type: Date,}, // 读数时间；

     machine_status : {type: Number, enum: [1,2,3], default: 1},//设备状态 1、正常 2、异常、3中止

     status: {type: Number, enum: [1,2,], default: 1},  //状态 1、正常 2、删除
 
     create_at: { type: Date, default: Date.now, index: -1,select: true },
     update_at: { type: Date, default: Date.now ,select: true},
 })
 
 
 EquipmentSchema.pre('save', function (next) {
     let now = new Date()
     this.update_at = now
     
     next()
 })
 
 EquipmentSchema.pre('find', function (next) {
    // console.log("enter equipment find list", this)
    // console.log("equipment data", this.name)
    next()
})
 
 mongoose.model('equipment', EquipmentSchema)
 module.exports = EquipmentSchema
 